#include <bits/stdc++.h>
using namespace std;
int n;
int q;
int ans;
int a[1000005] = {};
int cnt[1000005] = {};
set <int> s;
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin >> q;
    for(int t = 1;t <= q;t++)
    {
        ans = 0;
        s.clear();
        memset(cnt,0,sizeof(cnt));
        memset(a,0,sizeof(a));
        cin >> n;
        for(int i = 1;i <= n;i++)
        {
            cin >> a[i];
            cnt[a[i]]++;
            s.insert(a[i]);
        }
        for(auto i : s)
            if(cnt[i] > 1)
                ans += i * (cnt[i] - 1);
        cout << ans << "\n";
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
